package stock.observers.Imp;

import stock.chart.Chart;
import stock.entity.PriceQuote;
import stock.entity.TradingStatus;
import stock.observers.Display;
import stock.observers.Observer;
import stock.subjects.Subject;

import java.math.BigDecimal;
import java.time.Instant;

public class AlertObserver implements Observer, Display {

    private Subject subject;
    /** 股票代码（如 AAPL） */
    private String stockticker;
    /** 股票名称（如 Apple Inc.） */
    private String stockname;
    /** 最小交易单位/每手股数 */
    private int tradesize;
    /** 交易状态 */
    private TradingStatus tradingstatus;
    /** 最新行情快照 */
    private PriceQuote latestQuote;
    /** 最近一次实体更新的时间 */
    private Instant time;
    /** 总市值（与业务币种口径一致） */
    private BigDecimal marketCap;
    /** 数据来源标识（如 Refinitiv、ExchangeFeed） */
    private String dataSource;
    private Chart chart;

    public AlertObserver(Subject subject){
        this.subject = subject;
        subject.RegisterObserver(this);
    }

    @Override
    public void display() {
        System.out.printf("结果已更新：");
        System.out.printf("股票代码：%s\n", stockticker);
        System.out.printf("股票名称：%s\n", stockname);
        System.out.printf("最小交易单位/每手股数：%d\n", tradesize);
        System.out.printf("交易状态：%s\n", tradingstatus);
        System.out.printf("最新行情快照：%s\n", latestQuote);
        System.out.printf("最近一次实体更新的时间：%s\n", time);
        System.out.printf("总市值：%s\n", marketCap);
        System.out.printf("数据来源标识：%s\n", dataSource);
        if (chart != null) {
            System.out.printf("图表：%s\n", chart.getDescription());
        }
    }

    @Override
    public void update(String stockticker, String stockname, int tradesize, TradingStatus tradingstatus, PriceQuote latestQuote, Instant time, BigDecimal marketCap, String dataSource, Chart chart) {
        this.stockticker = stockticker;
        this.stockname = stockname;
        this.tradesize = tradesize;
        this.tradingstatus = tradingstatus;
        this.latestQuote = latestQuote;
        this.time = time;
        this.marketCap = marketCap;
        this.dataSource = dataSource;
        if (chart != null) {
            this.chart = chart;
        }
        display();
    }
}